package dataS.doubleLinked;

public class DoubleLinked {
    public DoubleNode head;
    public DoubleNode tail;

    public DoubleLinked(){
        head=null;
        tail=null;
    }
    //从头部插入
    public void insertFromHead(int val){
        DoubleNode doubleNode=new DoubleNode(val);
        if(head==null){
            head=doubleNode;
            tail=doubleNode;
        }else {
            head.before=doubleNode;
            doubleNode.after=head;

            head=doubleNode;
        }

    }

    //遍历节点
    public void display() {
        //创建一个临时节点
        DoubleNode tmp = head;
        while (tmp!= null){
            System.out.print(tmp.val + " ");
            tmp = tmp.after;
        }
        System.out.println();

    }
}
